#!/usr/bin/perl -w

#  FILE:   structure.pl
#  AUTHOR: Ruth Cobos
#  DATE:   15/02/01
#
#  DESCRIPTION: Muestra la lista de estructuras en fase inicial o la estructura definitiva e n la fase activa

# COMENTARIOS/PROBLEMAS:
# - a lo mejor vendria bien que cuando se pinche en un tema se refrescasen solo los frames de la parte
#   de description y la barra de botones

#inicializar:
require ("init.pl");
require ("dbData.pl");
require ("dbStruct.pl");
require "gui.pl";

#imprimir cabecera
&print_header;

#Se procesa la entrada al script
%input = &parse_input;

#Se obtienen los datos de entrada
$dbName = $input{b};
$idTopic = $input{t};
$idUser = $input{u};
#Se obtiene la fase actual
$phase = &get_phase($dbName);

if ($phase == 0)
{
  $idStructure = $input{s};

  #Se obtienen los datos del tema en cuestion
  %data = &get_data($dbName, "Struct", "idTopic", $idTopic);
}
if ($phase == 1)
{
  $idStructure = 0;
  #Se obtienen los datos del tema en cuestion
  %data = &get_data($dbName, "Topic", "idTopic", $idTopic);
}

#Se obtiene el URL del tema en cuestion
$URL = $data{URL.1};
#Se obtiene el path de los frames a mostrar
$path = &get_path($URL);
$server = $ENV{'SERVER_NAME'};

($dbLanguage, $IMG) = &get_language($dbName);

#Obtener los datos de la leyenda
%data = &get_data($dbLanguage, "Message", "name", "\'legend\'");
$legend = $data{'txt'.1};
%data = &get_data($dbLanguage, "Message", "name", "\'yesSuscrip\'");
$yesSuscrip = $data{'txt'.1};
%data = &get_data($dbLanguage, "Message", "name", "\'noSuscrip\'");
$noSuscrip = $data{'txt'.1};

#Ayuda
%H = &get_data($dbLanguage, "HelpMsg", "name", "\'helpK\'");
$altHelp = $H{'txt'.1};

#Obtener los textos a mostrar en la fase inicial
%form = &get_data ($dbLanguage, "MyForm", "name", "\'structureS\'");
$title = $form{'title'.1};
$txtTypeS = $form{fSuperTopic.1};
$txtTypeS2 = $form{fValue.1};
$txtThisS = $form{fTopic.1};

if ($idStructure > 0)
{
  %dGD = &get_data($dbName, "GeneralData", "idGeneralData", 1);
  $RankingStructure = $dGD{RankingStructure.1};
  $rootName =  $dGD{rootName.1};

  print <<EOF1;
  <HTML><HEAD><BASE TARGET="descriptions"></HEAD><BODY BGCOLOR="#FFFFFF" BACKGROUND="../$IMG/kc.gif"><BR>
  <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=5>
EOF1
  ;

  %idStructs = &get_struct($dbName);

  if ($idStructs{numRows} > 1)
  {
    print "\n<TR><TD COLSPAN=2><H4>$txtTypeS";
    if ($RankingStructure eq '1')
    {
      print "\n$txtTypeS2.</H4></TD>";
    }
    else
    {
      print "</H4></TD>";
    }


    print "\n<TR><TD COLSPAN=2>";


    foreach $i (1 .. $idStructs{numRows})
    {
      $idS = $idStructs{'s'.$i};
      if ($idS != $idStructure)
      {
        $structure = $path . "structureS.pl?b=$dbName&t=$idTopic&s=$idS&u=$idUser";
        print "\n<A HREF=\"$structure\" TARGET=\"structure\"><FONT SIZE=\"+1\">$idS</FONT></A>";
        if ($RankingStructure eq '1')
        {
          print "[$idStructs{'favour'.$i}|$idStructs{'against'.$i}]&nbsp;&nbsp;";
        }
      }
      else
      {
        $inFavour = $idStructs{'favour'.$i};
        $inAgainst = $idStructs{'against'.$i};
      }
    }


    print "\n</TD><TR><TD><H4>$txtThisS</H4></TD>";
    print "\n<TD><FONT SIZE=\"+2\"> $idStructure</FONT>";

    if ($RankingStructure eq '1')
    {
      print "[$inFavour|$inAgainst]</TD>";
    }

    print "\n</TABLE><BR><FONT SIZE=\"-1\">";

    &showNewTreeS($dbName, 0, $idTopic, $phase, $idStructure, $idUser);
  }
  else
  {
    print "<H4>$title:<br><H4>";
    print "<H3>$rootName</H3>";
  }


  print "</FONT>";
}
else
{
  print "<HTML>\n<HEAD><BASE TARGET=\"descriptions\"></HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" BACKGROUND=\"../" . $IMG . "/kc.gif\">\n";  
  print "<FONT SIZE=\"-1\">";
  &showNewTreeS($dbName, 0, $idTopic, $phase, $idStructure, $idUser);
}

  print "</FONT>";
  printf <<EOF1;
<br><br>
<hr>
<table border="0" width="225">
  <tr>
    <td width="100%" bgcolor=$spaceColors{dark_3}>
      <p align="center"><b><font color="#FFFFFF" face="Arial">$legend</font></b></td>
  </tr>
  <tr>
    <td width="100%" bgcolor=$spaceColors{bright_3}><IMG SRC="imgTreeJS/folderGreen.gif" width="19" height="16">
      <b>
      <font color="#FFFFFF" face="Arial" size="2">$yesSuscrip</font></b><BR>
      <IMG SRC="imgTreeJS/folderRed.gif" width="19" height="16">   <font face="Arial" size="2" color="#FFFFFF"><b>$noSuscrip</b></font></td>
  </tr>
</table>
EOF1
;

print"\n</BODY></HTML>";


#Help
#&print_help($dbName, 'consinfo.htm#consultar_estructura', 'helpK');
